﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Diagnostics.Contracts;
using SimpleIR;

namespace PInfoModel
{
	/// <summary>
	/// The complete information (all call contexts all methods) for the full program.
	/// </summary>
	public sealed class CompleteAnalysisInfoForProgram
	{
		/// <summary>
		/// The program that the results are for
		/// </summary>
		public IRProgram Program;

		/// <summary>
		/// A map from methods to the analysis results for them.
		/// </summary>
		public Dictionary<IRInvokeIdentity, CompleteAnalysisInfoMethod> MethodInfo;

		public CompleteAnalysisInfoMethodContext CurrentContext;

		public bool DoProgPointInfoCompute;

		public Dictionary<int, ProgramPointInfo> CurrentProgramPointInfo;

		[ContractInvariantMethod]
		private void ObjectInvariant()
		{
			Contract.Invariant(this.Program != null);
			Contract.Invariant(this.MethodInfo != null);
		}

		public CompleteAnalysisInfoForProgram(IRProgram prog, Dictionary<IRInvokeIdentity, CompleteAnalysisInfoMethod> mmap, bool computeprogpointinfo)
		{
			this.Program = prog;
			this.MethodInfo = mmap;
			this.DoProgPointInfoCompute = computeprogpointinfo;
		}

		/// <summary>
		/// Get the analysis context for the specified method and contextid.
		/// </summary>
		public CompleteAnalysisInfoMethodContext LookupInfoForMethodAndContext(IRInvokeIdentity iiv, int contextid)
		{
			CompleteAnalysisInfoMethod mm = this.MethodInfo[iiv];
			CompleteAnalysisInfoMethodContext ccr = mm.AllCallContexts.Find((CompleteAnalysisInfoMethodContext cc) => cc.ContextID == contextid);

			return ccr;
		}
	}
}
